package com.tim.wicket.examples;

import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;

import com.tim.wicket.examples.model.Address;
import com.tim.wicket.examples.model.Cart;

public class CheckOut extends CheesrPage {
	public CheckOut() {
		add(new FeedbackPanel("feedback"));
		
		IModel<Address> address = new CompoundPropertyModel<Address>(getCart().getBillingAddress());

		Form<Address> form = new Form<Address>("form", address);
		
		form.add(new TextField<String>("name").setRequired(true));
		form.add(new TextField<String>("street").setRequired(true));
		form.add(new TextField<Integer>("zipcode").setRequired(true));
		form.add(new TextField<String>("city").setRequired(true));
		
		form.add(new Link<Void>("cancel") {
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick() {
				setResponsePage(Index.class);
			}
		});
		
		form.add(new Button("order") {
			private static final long serialVersionUID = 1L;

			@Override
			public void onSubmit() {
				Cart cart = getCart();
				
				// charge customer's credit card and ship cheeses
				cart.getCheeses().clear();
				
				setResponsePage(Index.class);
			}
		});
		
		add(form);
	}
}
